//
//  QuotesTopSectionView.m
//  CBT
//
//  Created by 四点钟 on 2018/11/17.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "QuotesTopSectionView.h"

@interface QuotesTopSectionView()

@property (nonatomic, strong) UIView *rootView;
@property (nonatomic, strong) UIImageView *rootImageView;

@property (nonatomic, strong) UILabel *coinLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *gainLabel;

@property (nonatomic, strong) UIView *lineView;

@end

@implementation QuotesTopSectionView

-(instancetype)initWithFrame:(CGRect)frame withImageName:(NSString *)name
{
    if (self == [super initWithFrame:frame]) {
        [self initSubViewsWithName:name];
    }
    return self;
}

- (void)initSubViewsWithName:(NSString *)name
{
    _rootView = [[UIView alloc]init];
    _rootView.backgroundColor = [UIColor clearColor];
    [self addSubview:_rootView];
    
    _rootImageView = [[UIImageView alloc]init];
    _rootImageView.image = [UIImage imageNamed:name];
    [_rootView addSubview:_rootImageView];
    
    _coinLabel = [[UILabel alloc]init];
    _coinLabel.font = [UIFont systemFontOfSize:16];
    _coinLabel.textColor = DefaultPurpleColor;
    [_rootView addSubview:_coinLabel];
    
    _priceLabel = [[UILabel alloc]init];
    _priceLabel.font = [UIFont systemFontOfSize:16];
    _priceLabel.textColor = DefaultPurpleColor;
    [_rootView addSubview:_priceLabel];
    
    _gainLabel = [[UILabel alloc]init];
    _gainLabel.font = [UIFont systemFontOfSize:16];
    _gainLabel.textAlignment = NSTextAlignmentRight;
    _gainLabel.textColor = DefaultPurpleColor;
    [_rootView addSubview:_gainLabel];
    
    _lineView = [[UIView alloc]init];
    _lineView.backgroundColor = LineViewBgColor;
    [_rootView addSubview:_lineView];
    
    [self detaultInfo];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    @weak(self)
    [_rootView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [_rootImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(0);
    }];
    
    [_coinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
    make.width.mas_equalTo(self_weak_.rootView.mas_width).multipliedBy(0.44347826);
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self_weak_.coinLabel.mas_right);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(self_weak_.rootView.mas_width).multipliedBy(0.22608696);
    }];
    
    [_gainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self_weak_.priceLabel.mas_right);
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(self_weak_.rootView.mas_width).multipliedBy(0.23478261);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(50);
        make.height.mas_equalTo(1);
    }];
}

- (void)detaultInfo
{
    _coinLabel.text  = kLocalizedString(@"币种", nil);
    _priceLabel.text = kLocalizedString(@"时价", nil);
    _gainLabel.text  = kLocalizedString(@"涨跌幅", nil);
}

- (void)changeLanguage {
    [self detaultInfo];
}

@end
